package net.expectx.gw.service.impl;

import net.expectx.common.base.BaseResult;
import net.expectx.gw.mapper.SystemTypeMapper;
import net.expectx.gw.bean.SystemType;
import net.expectx.gw.service.SystemTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SystemTypeService实现
 * @author lijian
 * @date 2019/1/18
 */
@Service
public class SystemTypeServiceImpl extends BaseServiceImpl<SystemType> implements SystemTypeService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SystemTypeServiceImpl.class);

    @Autowired
    SystemTypeMapper systemTypeMapper;
    @Override
    public BaseResult insertSelective(SystemType record) {


        Map<String, Object>map=new HashMap<>(2);
        String msg;
        boolean flag=false;
        List<SystemType> systemTypes =  systemTypeMapper.findByAttr("type_name ='"+record.getTypeName()+"' and type_group_id in ("+record.getTypeGroupId()+")", null);
        if (systemTypes.isEmpty()){
            return super.insertSelective(record);
        }else{
            msg = "输入的名称已存在,请重新输入!";
        }
        return new BaseResult(false, msg, null);
    }

    @Override
    public BaseResult updateByPrimaryKeySelective(SystemType record) {
        Map<String, Object>map=new HashMap<>(2);
        String msg;
        boolean flag=false;
        List<SystemType> SystemTypes = systemTypeMapper.findByAttr("id not in('"+record.getId()+"') and type_name  in('"+record.getTypeName()+"') and type_group_id in ("+record.getTypeGroupId()+")", null);
        if (SystemTypes.isEmpty()){
            return super.updateByPrimaryKeySelective(record);
        }else{
            msg = "输入的名称已存在,请重新输入!";
        }
        return new BaseResult(false, msg, null);
    }
}
